#ifndef AUDIORECORDER_H
#define AUDIORECORDER_H

#include <QtCore/QObject>
#include <QAudioRecorder>

#include "../global/xnamespace.h"

class QQmlEngine;
class QJSEngine;

X_BEGIN_NAMESPACE

// 音频录音器
class AudioRecorder : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
    Q_PROPERTY(bool paused READ paused NOTIFY pausedChanged)
    Q_PROPERTY(QString fileName READ fileName NOTIFY fileNameChanged)

signals:
    void recordCompleted(QString fileName);

    void recordingChanged(bool recording);
    void pausedChanged(bool paused);
    void fileNameChanged(QString fileName);

public:
    explicit AudioRecorder(QObject *parent = 0);

    static AudioRecorder& instance();
    static const char* qmlName();
    static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);

    Q_INVOKABLE bool recording() const;
    Q_INVOKABLE bool paused() const;
    Q_INVOKABLE bool stopped() const;
    Q_INVOKABLE QString fileName() const;

public slots:
    Q_INVOKABLE void start();
    Q_INVOKABLE void pause();
    Q_INVOKABLE void stop();

private:
    static AudioRecorder *createInstance();

private:
    QAudioRecorder m_audioRecorder;

    QString m_codec;
    QString m_fileName;
    QMultimedia::EncodingQuality m_encodingQuality;
};

X_END_NAMESPACE

#endif // AUDIORECORDER_H
